from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options


service = Service(executable_path='D:\\chromedriver.exe')
options = Options()

# 防检测
# options.add_argument("--disable-blink-features=AutomationControlled")
options.add_experimental_option('excludeSwitches', ['enable-automation'])

# 无头 与设置UA
# options.add_argument('--headless')
# options.add_argument('user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36')

# 设置移动端模式
# mobile_emulation = {
#     "deviceMetrics": {"width": 375, "height": 812, "pixelRatio": 3.0},
#     "userAgent": "Mozilla/5.0 (Linux; Android 10; Pixel 4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.105 Mobile Safari/537.36"
# }
# options.add_experimental_option("mobileEmulation", mobile_emulation)

# 禁止加载图片
# options.add_argument("--blink-settings=imagesEnabled=false")

# 禁用js
# options.add_argument("--disable-javascript")

print(options.arguments)

driver = webdriver.Chrome(service=service, options=options)

driver.maximize_window()


driver.get("https://www.cninfo.com.cn/")

print(driver.page_source)
input()
driver.quit()